package com.qingcloud.df.executor.cluster;

import com.qingcloud.df.executor.consumer.HeartbeatConsumer;
import com.qingcloud.df.executor.consumer.TaskQueue;
import com.qingcloud.df.sdk.component.message.NodeInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class ServerChecker {
    public static final Logger logger = LoggerFactory.getLogger(ServerChecker.class);

    private final TaskQueue<NodeInfo> queue;
    public ServerChecker() {
        this.queue = new TaskQueue<>(0L, 64);
        HeartbeatConsumer consumer = new HeartbeatConsumer(0L, 1,16,"heartbeat-executor", 50,"heartbeat-consumer",this.queue);
        consumer.start();
    }

    public void submit(NodeInfo nodeInfo) {
        try {
            this.queue.submit(nodeInfo);
        } catch (InterruptedException e) {
            logger.error("executor heartbeat submit failed!", e);
        }
    }
}
